/*
 * @Description: 
 * @Version: 0.0
 * @Author: taosong
 * @Date: 2023-12-11 19:56:32
 * @LastEditors: taosong
 * @LastEditTime: 2023-12-11 20:18:58
 */
// 单件设计模式1  立即创建/饿汉式单件模式
class DateUtil {
  static dateUtil = new DateUtil()
  private constructor() {
    console.log('创建对象1')
  }
  formatDate() {}
  diffDateByDay() {}
  timeConversion(restTime: string) {}
}


console.log('abc')

// 用的都是同一个对象   外部无法定义对象
// const dateUtil = DateUtil.dateUtil
// const dateUtil1 = DateUtil.dateUtil


// 单件设计模式2  不会立即执行 方法式单件设计模式
class DateUtil2 {
  static dateUtil: DateUtil2
  static geInstance() {
    if (!this.dateUtil) {
      this.dateUtil = new DateUtil2()
    } 
    return this.dateUtil
  }
  private constructor() {
    console.log('创建对象2')
  }
  formatDate() {}
  diffDateByDay() {}
  timeConversion(restTime: string) {}
}

const dateUtil2 = DateUtil2.geInstance()
const dateUtil3 = DateUtil2.geInstance()
console.log(dateUtil2 === dateUtil3)